package com.g4.shoppingback.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;

/**
 * 令牌配置类
 */
@Configuration
public class TokenConfig {

    private String key ="miShop"; //令牌签名的自定义密钥

    /**
     * 配置令牌类型
     * @return 令牌对象
     */
    @Bean
    public TokenStore tokenStore(){
        JwtTokenStore tokenStore = new JwtTokenStore(jwtAccessTokenConverter()); //创建JWT令牌
        return tokenStore;
    }

    /**
     * 配置JWT令牌
     * @return
     */
    @Bean
    public JwtAccessTokenConverter jwtAccessTokenConverter() {
        JwtAccessTokenConverter tokenConverter = new JwtAccessTokenConverter(); //创建JWT令牌转换器配置令牌
        tokenConverter.setSigningKey(key);   //设置令牌签名
        return tokenConverter;
    }
}
